package com.example.mdoncall;

import android.content.BroadcastReceiver;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;

/**
 * 
 * @author Anthony Maniquiz & Laine Nicolas (Smart Telecom Inc. OJT) 
 * @version 1
 * 
 */

public class IncomingCallReceiver extends BroadcastReceiver {

	String phonenumber;

        @Override
        public void onReceive(Context context, Intent intent) {
                Bundle bundle = intent.getExtras();
                
                if(null == bundle)
                        return;
                
                String state = bundle.getString(TelephonyManager.EXTRA_STATE);
                
                if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING)) {
                        phonenumber = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
                        
                        intent = new Intent(context, ToastActivity.class);
               		 	intent.addFlags(Intent.FLAG_FROM_BACKGROUND); 
                        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
               		 	intent.putExtra("search", phonenumber);
                        context.startActivity(intent);
                		}
        	}
}
